package Ants.Model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class Tile {
	
    private final int row;
    private final int col;
    private List<Tile> successors;
    
    //Resettate all'update
    private Type type;
    private Ant ant;
    
    //Per la BFS del cibo, esplorazione ecc. 
    private boolean marked = false;
    private Tile parent;
    private int dist = 0;
    private int fogLevel = 0;
    private int f = 0;
    private boolean checked;
    private int distanceToTarget;

	public Tile(int rows, int cols){
		this.row = rows;
		this.col = cols;
		this.successors = new ArrayList<Tile>();
		this.setType(Type.LAND);
	}

	public List<Tile> getSuccessors() {
		return successors;
	}

	public void setSuccessors(List<Tile> successors) {
		this.successors = successors;
	}

	public void removeSuccessor(Tile tile){
		List<Tile> newSuccessors = new ArrayList<Tile>();
		for (Tile  t : successors) {
			if(t!=tile)
				newSuccessors.add(t);
		}
		successors = newSuccessors;
	}
	
	public int getRow() {
		return row;
	}

	public int getCol() {
		return col;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	public Ant getAnt() {
		return ant;
	}

	public void setAnt(Ant ant) {
		this.ant = ant;
	}   
	
	public boolean isMarked() {
		return marked;
	}

	public void setMarked(boolean marked) {
		this.marked = marked;
	}
	
	public Tile getParent() {
		return parent;
	}

	public void setParent(Tile parent) {
		this.parent = parent;
	}

	public int getDist() {
		return dist;
	}

	public void setDist(int dist) {
		this.dist = dist;
	}
	
	@Override
	public String toString() {
		return "R"+row+" C"+col;
	}

	public int getFogLevel() {
		return fogLevel;
	}

	public void setFogLevel(int fogLevel) {
		this.fogLevel = fogLevel;
	}
	
	public void increaseFogLevel() {
		++fogLevel;
	}

	public int getF() {
		return f;
	}

	public void setF(int f) {
		this.f = f;
	}
	
	public boolean isChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}
	
	public int getDistanceToTarget() {
		return distanceToTarget;
	}

	public void setDistanceToTarget(int distanceToTarget) {
		this.distanceToTarget = distanceToTarget;
	}

	public static int GetDistRow(Tile a,Tile b){
		int deltaRow = Math.abs(a.getRow() - b.getRow());
		return Math.min(deltaRow,Status.Rows - deltaRow);
	}

	public static int GetDistCol(Tile a,Tile b){
		int deltaCol = Math.abs(a.getCol() - b.getCol());
		return Math.min(deltaCol,Status.Cols - deltaCol);
	}

}



